package jMiiEditor.mii.checker;

import jMiiEditor.mii.Mii;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class MiiCheckerResult implements Serializable
{
    private static final long serialVersionUID = 1L;
    /** @serial */
    private MiiCheckerFileObject miiCheckerFileObject;
    /** @serial */
    private Mii                  mii;
    /** @serial */
    private List<Entry>          actionPerfomedList = new ArrayList<Entry>();

    public MiiCheckerResult()
    {
        // empty !
    }

    public MiiCheckerFileObject getMiiCheckerFileObject()
    {
        return this.miiCheckerFileObject;
    }

    public void setMiiCheckerFileObject( MiiCheckerFileObject miiCheckerFileObject )
    {
        this.miiCheckerFileObject = miiCheckerFileObject;
    }

    public void setMii( Mii mii )
    {
        this.mii = mii;
    }

    public Mii getMii()
    {
        return mii;
    }

    public void addAction( String actionDescription )
    {
        actionPerfomedList.add( new Entry( actionDescription ) );
    }

    public void addException(
            MiiCheckerProposal aMiiCheckerProposal,
            MiiCheckerActionException cause
            )
    {
        actionPerfomedList.add( new Entry( aMiiCheckerProposal.getMessageAction(), cause ) );
    }

    public List<Entry> getActionPerfomed()
    {
        return Collections.unmodifiableList( actionPerfomedList );
    }

    /* (non-Javadoc)
     * @see java.lang.Object#toString()
     */
    @Override
    public String toString()
    {
        final int maxLen = 10;
        StringBuilder builder = new StringBuilder();
        builder.append( "MiiCheckerResult [miiCheckerFileObject=" );
        builder.append( miiCheckerFileObject );
        builder.append( ", mii=" );
        builder.append( mii );
        builder.append( ", actionPerfomedList=" );
        builder.append( actionPerfomedList != null ? actionPerfomedList
                .subList( 0, Math.min( actionPerfomedList.size(), maxLen ) )
                : null );
        builder.append( "]" );
        return builder.toString();
    }

    public class Entry implements Serializable
    {
        private static final long serialVersionUID = 1L;
        /** @serial */
        private String description;
        /** @serial */
        private MiiCheckerActionException cause;

        public Entry( String description )
        {
            this.description = description;
        }

        public Entry(
                String description,
                MiiCheckerActionException cause
                )
        {
            this.description = description;
            this.cause       = cause;
        }

        /**
         * @return the description
         */
        public String getDescription()
        {
            return description;
        }

        /**
         * @return the cause
         */
        public MiiCheckerActionException getCause()
        {
            return cause;
        }

        /* (non-Javadoc)
         * @see java.lang.Object#toString()
         */
        @Override
        public String toString()
        {
            StringBuilder builder = new StringBuilder();

            builder.append( "Entry [description=" );
            builder.append( description );

            if( cause != null ) {
                builder.append( ", cause=" );
                builder.append( cause );
            }
            builder.append( "]" );

            return builder.toString();
        }
    }
}
